package yannan.voiplock4ble.utils;

import android.content.Context;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

/**
 * Created by PC on 2016/11/30.
 */
public class AnimUtils {
    private final static String TAG = "AnimUtils";
    private static AlphaAnimation alphaAnimation1;

    /**
     * 执行动画
     *
     * @param oldRel
     * @param newRel
     */
    public static void doAnimation(Context context, View oldRel, View newRel) {
        oldRel.startAnimation(AnimationUtils.makeOutAnimation(context, false));
        oldRel.setVisibility(View.GONE);
        newRel.startAnimation(AnimationUtils.makeInAnimation(context, false));
        newRel.setVisibility(View.VISIBLE);
    }

    /**
     * 渐变动画
     *
     * @param oldRel
     * @param newRel
     */
    public static void alphaAnimation(final View oldRel, final View newRel) {
        AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
        alphaAnimation.setDuration(1000);
        alphaAnimation.setFillAfter(true);
        oldRel.startAnimation(alphaAnimation);
        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                oldRel.setVisibility(View.GONE);
                alphaAnimation1 = new AlphaAnimation(0.0f, 1.0f);
                alphaAnimation1.setDuration(1000);
                alphaAnimation1.setFillAfter(true);
                newRel.startAnimation(alphaAnimation1);
                newRel.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });

    }
}
